package com.xgure.controller.admin;

import com.xgure.dto.EmployeeLoginDTO;
import com.xgure.dto.EmployeeRegisterDTO;
import com.xgure.dto.EmployeeUpdateDTO;
import com.xgure.pojo.Employee;
import com.xgure.result.Result;
import com.xgure.service.EmployeeService;
import com.xgure.vo.EmployeeLoginVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/admin/employee")
@Slf4j
public class EmployeeController {

    @Resource
    private EmployeeService employeeService;

    /**
     * 员工登录
     *
     * @return null则表示登录成功，否则表示登录失败
     */
    @PostMapping("/login")
    public Result<EmployeeLoginVO> login(@RequestBody EmployeeLoginDTO employeeDTO) {
        log.info("员工登录：{}", employeeDTO);
        EmployeeLoginVO employeeLoginVO = employeeService.login(employeeDTO);
        return Result.success(employeeLoginVO);
    }

    /**
     * 员工注册
     *
     */
    @PostMapping("/register")
    public Result register(@RequestBody EmployeeRegisterDTO employeeRegisterDTO) {
        log.info("员工注册：{}", employeeRegisterDTO);
        employeeService.register(employeeRegisterDTO);
        return Result.success();
    }

    /**
     * 员工信息更新
     *
     * @return 员工信息
     */
    @PutMapping("/update")
    public Result<Employee> update(@RequestBody EmployeeUpdateDTO employeeUpdateDTO) {
        log.info("员工更新：{}", employeeUpdateDTO);
        Employee employee = employeeService.update(employeeUpdateDTO);
        return Result.success(employee);
    }

    /**
     * 根据员工姓名查询员工
     *
     * @return 员工信息
     */
    @GetMapping("/info")
    public Result<Employee> getEmployeeByName(String name) {
        Employee employee = employeeService.getEmployeeByName(name);
        return Result.success(employee);
    }

}
